'use strict';
const db = uniCloud.database();
const favoritesCollection = db.collection('favorites');

exports.main = async (event, context) => {
	const { userId, courseId } = event;
	
	if (!userId || !courseId) {
		return {
			code: 1,
			message: '参数错误'
		};
	}
	
	try {
		const favorite = await favoritesCollection.where({
			userId,
			courseId
		}).get();
		
		return {
			code: 0,
			isFavorite: favorite.data.length > 0
		};
	} catch (error) {
		return {
			code: 1,
			message: '查询失败'
		};
	}
}; 